/*
 * Copyright 2022 MindMotion Microelectronics Co., Ltd.
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */


#ifndef __BOARD_INIT_H__
#define __BOARD_INIT_H__

#include <stdio.h>
#include <stdint.h>

#include "hal_common.h"
#include "hal_rcc.h"
#include "hal_uart.h"
#include "hal_tim.h"
#include "hal_flexcan.h"
#include "hal_gpio.h"

#include "clock_init.h"
#include "pin_init.h"

/* DEBUG UART. */
#define BOARD_DEBUG_UART_PORT        UART1
#define BOARD_DEBUG_UART_BAUDRATE    9600u
#define BOARD_DEBUG_UART_FREQ        CLOCK_APB2_FREQ

/* TIM1. */
#define BOARD_TIM_PORT               (TIM_Type *)TIM1
#define BOARD_TIM_IRQn               TIM1_UP_IRQn
#define BOARD_TIM_IRQHandler         TIM1_UP_IRQHandler
#define BOARD_TIM_FREQ               CLOCK_SYS_FREQ

/* FLEXCAN. */
#define BOARD_FLEXCAN_PORT           FLEXCAN1
#define BOARD_FLEXCAN_CLOCK_FREQ     CLOCK_APB1_FREQ
#define BOARD_FLEXCAN_RX_MB_CH       0u
#define BOARD_FLEXCAN_TX_MB_CH       2u
#define BOARD_FLEXCAN_RX_MB_INT      FLEXCAN_INT_MB_0
#define BOARD_FLEXCAN_TX_MB_INT      FLEXCAN_INT_MB_2
#define BOARD_FLEXCAN_IRQHandler     FlexCAN1_IRQHandler
#define BOARD_FLEXCAN_RX_MB_STATUS   FLEXCAN_STATUS_MB_0
#define BOARD_FLEXCAN_TX_MB_STATUS   FLEXCAN_STATUS_MB_2
#define BOARD_FLEXCAN_IRQn           FlexCAN1_IRQn

#define BOARD_FLEXCAN_XFER_MaxNum    15u /* Amount of mb to be used. */
#define BOARD_FLEXCAN_XFER_PRIORITY  0u /* Priority of the mb frame. */

void BOARD_Init(void);
int main_canopen(void);

#endif /* __BOARD_INIT_H__ */
